<?php
class Cryptor {
	
	private static function axor($source/*:String*/, $key/*:String*/)/*:String*/ {
	    if (!$key) return $source;
		$result = "";
		$keyLength = strlen($key);
	    for($i = 0; $i < strlen($source); $i++) {
	        $result .= chr(ord($source[$i]) ^ ord($key[$i % $keyLength]));
	    }
	    return $result;
	}
	
	public static function encode($source/*:String*/, $key/*:String*/="")/*:String*/ {
		return Cryptor::axor(base64_encode($source), $key);
	}
	
	public static function decode($source/*:String*/, $key/*:String*/="")/*:String*/ {
		return base64_decode(Cryptor::axor($source, $key));
	}
}
?>